import * as THREE from "three";
import { Shape, ShapeParams } from "./Shape";

export class BoxShape extends Shape {
    getRandomPosition(): THREE.Vector3 {
        const x = (Math.random() - 0.5) * (this.params.x || 1);
        const y = (Math.random() - 0.5) * (this.params.y || 1);
        const z = (Math.random() - 0.5) * (this.params.z || 1);
        return new THREE.Vector3(x, y, z).add(this.origin);
    }

    getRandomNormal(): THREE.Vector3 {
        // 默认返回六个面的法线之一
        const faces = [
            new THREE.Vector3(1, 0, 0),
            new THREE.Vector3(-1, 0, 0),
            new THREE.Vector3(0, 1, 0),
            new THREE.Vector3(0, -1, 0),
            new THREE.Vector3(0, 0, 1),
            new THREE.Vector3(0, 0, -1),
        ];
        return faces[Math.floor(Math.random() * faces.length)];
    }
}
